package com.example.chat

import androidx.compose.material.Text
import androidx.compose.ui.unit.ExperimentalUnitApi
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import androidx.navigation.navigation
import com.example.chat.view.ChatDetailScreen
import com.example.chat.view.ChatListScreen
import com.example.chat.view.ChatSearchScreen
import com.example.featuresdk.core.AbstractFeatureSDK
import com.example.featuresdk.viewmodel.NavigationViewModel


@OptIn(ExperimentalUnitApi::class)
fun NavGraphBuilder.chatNestedNavigationGraph(navigationViewModel: NavigationViewModel,
                                              featureSDK: AbstractFeatureSDK) {

    val featureKey = featureSDK.featureKey()

    navigation(startDestination = "${featureKey}/list", route = "$featureKey") {

        composable("${featureKey}/list") {
            ChatListScreen(navigationViewModel,featureSDK)
        }

        composable("${featureKey}/search") {
            ChatSearchScreen(navigationViewModel,featureSDK)
        }

        composable("${featureKey}/chatroom/{topicKey}?title={title}",
            arguments = listOf(
                navArgument("topicKey"){ type = NavType.StringType},
                navArgument("title"){
                    type = NavType.StringType
                    defaultValue = ""
                })){ backStackEntry ->
            ChatDetailScreen(backStackEntry.arguments?.getString("topicKey"),
                backStackEntry.arguments?.getString("title"),
                navigationViewModel,
                featureSDK)
        }

        composable("chat/edit"){
            Text("test")
        }
    }
}